package com.tsmti.doctor.service.impl;

import com.tsmti.core.common.query.data.Page;
import com.tsmti.core.common.query.data.PageImpl;
import com.tsmti.core.common.query.data.Queryable;
import com.tsmti.core.common.service.impl.BaseServiceImpl;
import com.tsmti.core.util.StringUtils;
import com.tsmti.doctor.entity.PimsPathologyRequisition;
import com.tsmti.doctor.dao.PimsPathologyRequisitionDao;
import com.tsmti.doctor.dto.RequisitionView;
import com.tsmti.doctor.service.PimsPathologyRequisitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package：com.tsmti.lab.service.impl
 * @Class：RequisitionServiceImpl
 * @Description： TODO
 * @Author：dcd
 * @Date：Created in 2018/11/13 11:17 AM
 * @Company:
 * @Version：
 * @Modified By:
 */
@Service("pimsPathologyRequisitionService")
public class PimsPathologyRequisitionServiceImpl extends BaseServiceImpl<PimsPathologyRequisition> implements PimsPathologyRequisitionService {
    @Autowired
    private PimsPathologyRequisitionDao pimsPathologyRequisitionDao;

    @Override
    public int getInReceiveListCount(RequisitionView model) {
        return pimsPathologyRequisitionDao.getInReceiveListCount(model);
    }

    @Override
    public Page<RequisitionView> getInReceiveList(RequisitionView model, Queryable queryable, int total) {
        List<RequisitionView> list = pimsPathologyRequisitionDao.getInReceiveList(model, queryable);
        return new PageImpl<RequisitionView>(list, queryable.getPageable(), total);
    }

    @Override
    public PimsPathologyRequisition getByRequisitionNo(String requisitionNo, String orgId) {
        StringBuffer sql = new StringBuffer();
        sql.append(" from PimsPathologyRequisition where requisitionNo = '" + requisitionNo + "'");
        if (StringUtils.isNotEmpty(orgId)) {
            sql.append(" and orgId ='" + orgId + "'");
        }
        List<PimsPathologyRequisition> list = findByHql(sql.toString());
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
